package com.example.livereplay.common.validator.user;

import com.example.livereplay.common.model.enity.SysUser;
import com.example.livereplay.exception.SysBusinessCode;
import com.example.livereplay.exception.SysBusinessException;
import com.example.livereplay.common.validator.BaseValidator;
import org.springframework.util.StringUtils;

public class SysUserValidator extends BaseValidator {
    public static void insertValidate(SysUser sysUser) {
        if (!StringUtils.hasText(sysUser.getUsername())) {
            throw new SysBusinessException(SysBusinessCode.USERNAME_EMPTY_ERROR);
        }
        if (!StringUtils.hasText(sysUser.getPassword())) {
            throw new SysBusinessException(SysBusinessCode.PASSWORD_EMPTY_ERROR);
        }
    }

    public static void updateValidate(SysUser sysUser) {
        if (!StringUtils.hasText(sysUser.getId())) {
            throw new SysBusinessException(SysBusinessCode.ID_EMPTY_ERROR);
        }
        if (!StringUtils.hasText(sysUser.getUsername())) {
            throw new SysBusinessException(SysBusinessCode.USERNAME_EMPTY_ERROR);
        }
    }
}
